<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="Generator" content="ALORK 20150428.01" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0"/>

<title><?php echo $this->_var['page_title']; ?></title>

<link rel="shortcut icon" href="favicon.ico" />
<link rel="icon" href="animated_favicon.gif" type="image/gif" />
<link rel="stylesheet" href="./public/my_style.css" />
<link rel="stylesheet" href="./public/register.css" />
<?php echo $this->smarty_insert_scripts(array('files'=>'./../js/jquery.js')); ?>
<script type="text/javascript" src="./../js/mobile-common.js"></script>
<body>
<script>
  autoWidth(720,320);
</script>
<?php echo $this->fetch('library/user_head.lbi'); ?>
<?php if ($this->_var['action'] == 'register'): ?>

<div id="register">
    <div class="box"><span class="left">手机号</span> <input type="text" placeholder="请输入11位手机号" name="mobile" class="mobile" onblur="is_registered(this.value);"/></div>
    <div class="box"><span class="left">验证码</span> <input type="text" placeholder="输入短信验证码" name="captcha" class="captcha"/><span class="right">
    <span class="get-captcha " onclick="get_captcha();">获取验证码</span>
    <span class="noget none">重发(60s)</span>
    </span></div>
    <div class="box"><span class="left">密码</span>   <input type="password" placeholder="6-16位的密码" name="password" id="password"/><span class="right"><span class="show" >显示</span></span></div>
    <div class="box"><span class="left">推荐人手机</span>   <input type="text" placeholder="邀请人手机号(可选)" name="recommend_mobile" id="recommend_mobile"/></div>
    
    <div class="register" onclick="register();">注册</div>
</div>
<script type="text/javascript">
/*检查密码*/
function password_check(){
  var password  = $('#password').val();
  if (password.length == 0)
  {
    point('密码不能为空',1);
    return false;
  }
  else if (password.length < 6)
  {
    point('密码不能少于6位',1);
    return false;
  }

  return true;
}
/*检查账号*/
function username_check(){
        var mobile  = $('.mobile').val();
        if (mobile.match('^[0-9]*[1-9][0-9]*$')&&mobile.length==11) {
            return true;
        }else{
            point('请输入正确的手机号',1);
            return false;
        }
}

function recommend_mobile_check(){
	var mobile  = $('#recommend_mobile').val();
        if (mobile.match('^[0-9]*[1-9][0-9]*$')&&mobile.length==11) {
            return true;
        }else{
            point('请输入正确的推荐人手机号',1);
            return false;
        }
}
/*检查验证码*/
function captcha_check(){
        var captcha  = $('.captcha').val();
        if (captcha.match('^[0-9]*[1-9][0-9]*$')&&captcha.length==6) {
            return true;
        }else{
            point('请输入正确的验证码',1);
            return false;
        }
}
/*检查账号是否存在*/
function is_registered(username){
    url="user.php?act=is_registered&r="+Math.random();
    htmlobj=$.post(url, {'username' : username}, function(data){
        if (data ==false) {
            point('用户名已存在',1);
        };
      },'JSON');
}
/*获取验证码*/
function get_captcha()
{
    var mobile  = $('.mobile').val();
    /*检查用户名是否合法*/
    username_check();
    if (!username_check()) {
      return false;
    };
    url="alone.php?act=send_sms&r="+Math.random();
    htmlobj=$.post(url, {'mobile' : mobile}, function(data){
        if (data.msg == 'OK') {
          $('.get-captcha').addClass('none');
          $('.noget').removeClass('none');
          curTime=60;
          InterValObj2 = setInterval('setCountdown()', 1000);
        }else{
          point(data.message,1);
        };
      },'JSON');
    return false;
}
/* 绑定成功等待时间 */
  function setCountdown(){
    if(curTime <= 0){
    $('.get-captcha').removeClass('none');
    $('.noget').addClass('none');
      clearInterval(InterValObj2);
    }else{
      curTime --;
      $('.noget').html('重发('+curTime+'s)');
    }
  }
  $('.show').toggle(
    function(){
      document.getElementById('password').type="text";
      $('.show').text('隐藏');
    },
    function(){
      document.getElementById('password').type="password";
      $('.show').text('显示');
    }
  );
/*ajax注册*/
function register(){
      var username = $('.mobile').val();
      var password = $('#password').val();
      var captcha  = $('.captcha').val();
      var recommend_mobile  = $('#recommend_mobile').val();
      username_check();
      password_check();
      captcha_check();
      if(recommend_mobile.length>0){
      	if(!recommend_mobile_check()){
      		return false;
      	}
      }
      if (!username_check()||!password_check()||!captcha_check()) {
        return false;
      };
      $.ajax({url:'user.php?act=ajax_register&',type:"POST",data:{username:username,password:password,captcha:captcha,recommend_mobile:recommend_mobile},dataType:"json",success:function(data){
        if (data.error>0) {
            point(data.message,1);
            return false;
        }else{
            point(data.message,1);
            window.location.href='user.php';
        };
      }});
}
</script>
<?php endif; ?>




<?php if ($this->_var['action'] == 'get_password'): ?>
<div id="get_password">
    <div class="box"><span class="left">手机号</span> <input type="text" placeholder="请输入11位手机号" name="mobile" class="mobile" onblur="is_registered(this.value);"/></div>
    <div class="register" onclick="get_captcha();">下一步</div>
</div>

<script>
    /*获取验证码*/
function get_captcha()
{
    var mobile  = $('.mobile').val();
    /*检查用户名是否合法*/
    username_check();
    url="./../alone.php?act=send_sms&r="+Math.random();
    htmlobj=$.post(url, {'mobile' : mobile}, function(data){
        if (data.msg == 'OK') {

        }else{
          point(data.content,1);
        };
      },'JSON');
    return false;
}
</script>

<?php endif; ?>
</body>
</html>
